home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.08 Aug 89 / POOPDraw Code ƒ / WIND Draw.c < prev   
Encoding:
C/C++ Source or Header  |  1989-06-12  |  5.7 KB  |  227 lines  |  [TEXT/KAHL]

  1. /********************************************************************/
  2. /*                        SOURCE CODE FILE                            */
  3. /********************************************************************/
  4. /*
  5. *   >>>    File name:        5.1 DrawWindow.c    
  6. *
  7. *      >>>    Purpose:        Methods for Rectangle Object
  8. *     >>>    Project:        PoopDraw    Version 1        
  9. *     >>>    Date:            2/20/89
  10. *      >>>    By:                Adam Treister
  11. *
  12. */
  13. /********************************************************************/
  14. /*    For Your Information            1802 Hillside Rd. SB CA 93101    */
  15. /********************************************************************/
  16.  
  17. #include "PoopDrawInc"
  18.  
  19. void DrawOutline(Rect r,int curTool);
  20.  
  21. typedef struct
  22. {
  23.     _StdObjectFields
  24.     ObjectHandle        drawPanel;
  25.     ControlHandle        vScrollBar,hScrollBar;    
  26.     Point                curOrigin;    
  27.     ObjectHandle        doc;                    /* info about files and printing */
  28.         
  29. } WindowDataRec,*WindowDataPtr,**WindowDataHandle;
  30.  
  31.  
  32. /***** Public Functions *********************************************/
  33. /*
  34. WindowPtr NewDrawWindow(void);    
  35. */
  36. /***** Private Functions ********************************************/
  37.  
  38. DrawWinDispatch(WindowDataHandle ObjectH,int message,LPtr ParmP);
  39. WindowPtr NewDrawWindow(void);
  40. private void Dispose(WindowPtr wP);
  41. private void MouseDown(WindowPtr wP);
  42. private void Grow(WindowPtr wP);
  43. private void KeyDown(WindowPtr wP);
  44. private void Update(WindowPtr wP);
  45. private void Activate(WindowPtr wP);
  46. private void DeActivate(WindowPtr wP);
  47. private WindowDataHandle GetWinData(WindowPtr    wP);    
  48.  
  49. /***** Local Defines & Includes *************************************/
  50.  
  51. #define UntitledWindowName    "\pUntitled"
  52.  
  53. /********************************************************************/
  54.  
  55. DrawWinDispatch(ObjectH,message,ParmP)
  56. WindowDataHandle ObjectH;
  57. int message;
  58. LPtr ParmP;
  59. {
  60.     WindowPtr wP;
  61.     wP = (*ObjectH)->port;
  62.     switch (message)
  63.     {
  64.         case CLOSE:    
  65.         case DISPOSE:            Dispose(wP);            break;
  66.         case MOUSEDOWN:            MouseDown(wP);            break;
  67.         case UPDATE:            Update(wP);                break;
  68.         case ACTIVATE:            Activate(wP);            break;
  69.         case DEACTIVATE:        DeActivate(wP);            break;
  70.         case GROW:                Grow(wP);                break;
  71.         default:                Dispatch((*ObjectH)->drawPanel,message,ParmP);    
  72.  
  73. }    }
  74.  
  75. /* ------------------------------------------------------------ */
  76. /*                                                                */
  77. /*                    New Draw Window                                */
  78. /*                                                                */
  79. /* ------------------------------------------------------------ */
  80.  
  81. WindowPtr NewDrawWindow()    
  82. {
  83.             WindowPtr        wP;                
  84.             Rect            BoundsRect;                    
  85.             WindowDataHandle WinData;                
  86.             extern Boolean DEBUG;
  87.             
  88.     BoundsRect = screenBits.bounds;
  89.     BoundsRect.top += 40;
  90.     
  91.     WinData = _GetHandleToRecord(WindowDataRec);
  92.     NullOutHandle(WinData);
  93.     wP = NewWindow (NULL, &BoundsRect, UntitledWindowName,
  94.                             true, documentProc, -1L,true, (long) WinData);
  95.     
  96.     SetPort(wP);
  97.     (*WinData)->port = wP;
  98.     (*WinData)->dispatch = DrawWinDispatch;
  99.  
  100.     New(DRAWPANEL,WinData,&(*WinData)->drawPanel);
  101.     return (wP);
  102. }
  103.  
  104. /* ------------------------------------------------------------ */
  105. /*                                                                */
  106. /*        Dispose Document Window                                    */
  107. /*                                                                */
  108. /*                                                                */
  109. /* ------------------------------------------------------------ */
  110.  
  111. void Dispose(wP)
  112. WindowPtr    wP;                
  113.  
  114. {
  115.         WindowDataHandle    TheWindowData = GetWinData(wP);            
  116.     
  117.     Dispatch((*TheWindowData)->drawPanel,DISPOSE,NULL);
  118.     DisposeHandle(TheWindowData);    
  119.     DisposeWindow(wP);
  120. }
  121.  
  122.  
  123. /* ------------------------------------------------------------ */
  124.  
  125. void MouseDown(wP)
  126. WindowPtr wP;
  127. {
  128.             short            PartCode;    
  129.             ControlHandle    ctrlH;    
  130.     extern    EventRecord         Event;
  131.     register Point            pt;
  132.             
  133.     pt = Event.where;
  134.     GlobalToLocal(&pt);
  135.     PartCode = FindControl(pt, wP, &ctrlH);
  136. /*    if (PartCode)
  137.         HandleScrollBars (wP,ctrlH,pt, PartCode); 
  138.     else 
  139. */    {
  140.             WindowDataHandle WinData = GetWinData(wP);
  141.         Dispatch((*WinData)->drawPanel,MOUSEDOWN,NULL);
  142.     }
  143. }
  144. /*------------------------------------------------------------------*/
  145.  
  146. void Grow(wP)
  147. WindowPtr wP;
  148. {
  149.             WindowDataHandle     WinData;                
  150.             long                newSize;
  151.             Rect                oldRect,growZone;
  152.             extern EventRecord    Event;
  153.             int                    newH,newV;
  154.             
  155.     WinData = GetWinData(wP);
  156.     growZone = screenBits.bounds;
  157.     growZone.left = 100;    growZone.top = 260;
  158.     newSize = GrowWindow(wP,Event.where,&growZone);
  159.     if (!newSize ) return;
  160.  
  161.      newH = LoWord(newSize);        newV = HiWord(newSize);
  162.     SizeWindow(wP,newH,newV,TRUE);
  163.     Dispatch((*WinData)->drawPanel,RESIZE,NULL);
  164.     ClipRect(&wP->portRect);
  165.     EraseRect(&wP->portRect);
  166.     InvalRect(&(wP->portRect));
  167. }
  168.  
  169. /* ------------------------------------------------------------ */
  170. /*                                                                */
  171. /*            Update                                    */
  172. /*                                                                */
  173. /*                                                                */
  174. /* ------------------------------------------------------------ */
  175.  
  176. void Update(wP)
  177. WindowPtr            wP;    
  178.  
  179. {
  180.     WindowDataHandle    WinData = GetWinData(wP);
  181.     Rect r;
  182.     
  183.     r = wP->portRect;
  184.     ClipRect(&r);
  185.     DrawControls(wP);        /* there are none, unless you add scrolling */
  186.     DrawGrowIcon(wP);
  187.     r.right -= ScrollBarWidth;    r.bottom -= ScrollBarWidth;
  188.     ClipRect(&r);
  189.     Dispatch((*WinData)->drawPanel,UPDATE,NULL);
  190. }
  191. /*--------------------------------------------------------------
  192. *        Activate    
  193. *----------------------------------------------------------------*/
  194.  
  195. void Activate(wP)
  196. WindowPtr            wP;    
  197. {
  198.     /* activation of controls goes here */
  199. }
  200.  
  201. /*--------------------------------------------------------------
  202. *        Deactivate    
  203. *----------------------------------------------------------------*/
  204. void DeActivate(wP)
  205. WindowPtr            wP;    
  206. {
  207.     /* deactivation of controls goes here */
  208. }
  209.  
  210.  
  211. /* ------------------------------------------------------------ */
  212. /*                                                                */
  213. /*                GetWindowDataHandle                                */
  214. /*                                                                */
  215. /*    This get the WindowDataHandle from the refCon field of        */
  216. /*    the window passed to the function.                             */
  217. /*                                                                */
  218. /* ------------------------------------------------------------ */
  219.  
  220.  
  221. WindowDataHandle GetWinData(wP)
  222. WindowPtr    wP;    
  223. {
  224.     return((WindowDataHandle) GetWRefCon(wP));
  225. }
  226.  
  227.